/*
 * FaceCat图形通讯框架
 * 著作权编号:2015SR229355+2020SR0266727
 * 上海卷卷猫信息技术有限公司
 */

using System;

namespace FaceCat {
    /// <summary>
    /// 年的按钮
    /// </summary>
    public class YearButton {
        /// <summary>
        /// 创建月的按钮
        /// </summary>
        /// <param name="calendar">日历视图</param>
        public YearButton(FCCalendar calendar) {
            m_calendar = calendar;
        }

        public FCRect m_bounds;

        /// <summary>
        /// 获取显示区域
        /// </summary>
        public virtual FCRect getBounds() {
            return m_bounds;
        }

        /// <summary>
        /// 设置显示区域
        /// </summary>
        public virtual void setBounds(FCRect value) {
            m_bounds = value;
        }

        public FCCalendar m_calendar;

        /// <summary>
        /// 获取日历视图
        /// </summary>
        public virtual FCCalendar getCalendar() {
            return m_calendar;
        }

        /// <summary>
        /// 设置日历视图
        /// </summary>
        public virtual void setCalendar(FCCalendar value) {
            m_calendar = value;
        }

        public bool m_visible = true;

        /// <summary>
        /// 获取是否可见
        /// </summary>
        public virtual bool isVisible() {
            return m_visible;
        }

        /// <summary>
        /// 设置是否可见
        /// </summary>
        public virtual void setVisible(bool value)
        {
            m_visible = value;
        }

        public int m_year;

        /// <summary>
        /// 获取年
        /// </summary>
        public virtual int getYear() {
            return m_year;
        }

        /// <summary>
        /// 设置年份
        /// </summary>
        public virtual void setYear(int value) {
            m_year = value;
        }

        /// <summary>
        /// 获取绘制的背景色
        /// </summary>
        /// <returns>背景色</returns>
        public virtual long getPaintingBackColor() {
            return FCColor.Back;
        }

        /// <summary>
        /// 获取绘制的边线颜色
        /// </summary>
        /// <returns>边线颜色</returns>
        public virtual long getPaintingBorderColor() {
            return FCColor.Border;
        }

        /// <summary>
        /// 获取要绘制的前景色
        /// </summary>
        /// <returns></returns>
        public virtual long getPaintingTextColor() {
            return FCColor.Text;
        }

        /// <summary>
        /// 触摸点击方法
        /// </summary>
        /// <param name="touchInfo">触摸信息</param>
        public virtual void onClick(FCTouchInfo touchInfo) {
            if (m_calendar != null) {
                m_calendar.setMode(FCCalendarMode.Month);
                m_calendar.getMonthDiv().selectYear(m_year);
                m_calendar.update();
                m_calendar.invalidate();
            }
        }

        /// <summary>
        /// 重绘背景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintBackGround(FCPaint paint, FCRect clipRect) {
            long backColor = getPaintingBackColor();
            paint.fillRect(backColor, m_bounds);
        }

        /// <summary>
        /// 重绘边线方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintBorder(FCPaint paint, FCRect clipRect) {
            long borderColor = getPaintingBorderColor();
            paint.drawLine(borderColor, 1, 0, m_bounds.left, m_bounds.bottom - 1, m_bounds.right - 1, m_bounds.bottom - 1);
            paint.drawLine(borderColor, 1, 0, m_bounds.right - 1, m_bounds.top, m_bounds.right - 1, m_bounds.bottom - 1);
        }

        /// <summary>
        /// 重绘前景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintForeground(FCPaint paint, FCRect clipRect) {
            int width = m_bounds.right - m_bounds.left;
            int height = m_bounds.bottom - m_bounds.top;
            String yearStr = m_year.ToString();
            FCFont font = m_calendar.getFont();
            FCSize textSize = paint.textSize(yearStr, font, -1);
            //创建渐变刷
            FCRect tRect = new FCRect();
            tRect.left = m_bounds.left + (width - textSize.cx) / 2;
            tRect.top = m_bounds.top + (height - textSize.cy) / 2;
            tRect.right = tRect.left + textSize.cx;
            tRect.bottom = tRect.top + textSize.cy;
            paint.drawText(yearStr, getPaintingTextColor(), font, tRect, -1);
        }
    }
}
